<template>
  <div class="wrap">
    <!-- 轮播图 start -->
    <el-carousel trigger="click" height="150px">
      <!-- 轮播项 start -->
      <el-carousel-item v-for="(item, index) in imgList" :key="item.id">
        <span class="go_back" v-show="index === 2" @click="toBack"
          >前往租车</span
        >
        <span class="welcom" v-show="index === 0"
          >欢迎您，尊敬的{{ user.uname }}用户</span
        >
        <span :class="swiperClass[index]">{{ item.content }}</span>
        <img :src="item.src" />
      </el-carousel-item>
      <!-- 轮播项 end -->
    </el-carousel>
    <!-- 轮播图 end -->

    <!-- 底部图片示区 -->
    <my-picture></my-picture>
  </div>
</template>

<script>
import Picture from '@/components/Picture.vue'
export default {
  data() {
    return {
      imgList: [
        {
          id: 0,
          content: '自行车出行，更环保、更健康',
          src: require('../assets/pic/swiper_two.jpg')
        },
        {
          id: 1,
          content: '生命在于运动，运动让生活更美好',
          src: require('../assets/pic/swiper_one.jpg')
        },
        {
          id: 2,
          content: '自行车租赁平台租车价格优惠，出行方便，是您最好的选择',
          src: require('../assets/pic/swiper_three.jpg')
        }
      ],
      swiperClass: ['span_one', 'span_two', 'span_three'],
      user: ''
    }
  },
  components: {
    'my-picture': Picture
  },
  mounted() {
    // 获取用户名
    this.user = JSON.parse(window.sessionStorage.getItem('user'))
  },
  methods: {
    // 跳转至租车菜单
    toBack() {
      this.$router.push({
        name: 'goods'
      })
    }
  }
}
</script>

<style lang="less" scoped>
// 主体样式
.wrap {
  margin: -20px;
}
.el-main {
  padding: 0px !important;
}
// 欢迎词样式
.welcom {
  color: #fff;
  margin-left: 15px;
  top: 10px;
}
// 轮播图样式
img {
  width: 100%;
  height: 100%;
}
// 轮播图文字样式
span {
  position: fixed;
  height: 70px;
  line-height: 70px;
  font-size: 22px;
}
.span_one {
  margin-left: 15px;
  top: 65px;
  color: #fff;
}
.span_two {
  right: 10px;
  bottom: 10px;
  color: #fff;
}
.span_three {
  margin-left: 10px;
  bottom: 0px;
  color: #a9a7a5;
}
.go_back {
  right: 10px;
  color: #a4b7a4;
  cursor: pointer;
}
</style>